<extend name="Public:index" />
<block name="mycss">
  <link href="__PUBLIC__/assets/plugins/dropify/css/dropify.min.css" rel="stylesheet">
  <link href="__PUBLIC__/assets/plugins/datatables/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
  <link href="__PUBLIC__/assets/plugins/datatables/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />
  <link href="__PUBLIC__/assets/plugins/datatables/rowReorder.bootstrap4.min.css" rel="stylesheet" type="text/css" />
  <style type="text/css">
    .shanchu {
      font-size: 21px;
      font-weight: 700;
      line-height: 1;
      color: #f00;
      text-shadow: 0 1px 0 #fff;
      opacity: .5;
      cursor: pointer;
    }

    .shanchu:hover {
      color: #f00;
      text-decoration: none;
      cursor: pointer;
      opacity: .9;
      filter: alpha(opacity=50)
    }

    .sort {
      cursor: move;
    }
    .table_tools>a{
     margin-right: 10px;
    }

    .chk,#chkall{
      zoom: 130%;
    }

    #bat_btn{
      display:block;
      margin: 3px 0 3px !important;
    }

    .lnk{
      color: #007bff;
    }
  </style>
</block>
<block name="main-content">
  <iframe name="ajaxifr" style="display:none;"></iframe>
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">

        <div class="card">
          <div class="card-body border-bottom">
            <div class="fro_profile">

              <div class="row">
                <div class="col-lg-4 mb-3 mb-lg-0">
                  <div class="fro_profile-main">
                    <div class="fro_profile-main-pic">
                      <empty name="pvo.img">
                        <img id="project_img" src="__PUBLIC__/assets/images/users/pro-1.png" alt="" class="rounded">
                        <else />
                        <img id="project_img" src="__ROOT__/Uploads/project/{$pvo.img}" alt="" class="rounded">
                      </empty>

                    </div>
                    <div class="fro_profile_user-detail ml-2">
                      <h5 class="fro_user-name">{$pvo.project_name}</h5>
                      <p class="mb-0 fro_user-name-post">{$pvo.project_addr}</p>

                    </div>
                  </div>
                </div>
                <!--end col-->

                <div class="col-lg-4 mb-3 mb-lg-0 mt-2">

                  <div class="row">
                    <div class="col-7">
                      <div class="header-title">项目阶段</div>
                      <div class="seling-report">

                        <h3 class="seling-data mb-1 text-info">{$pvo.project_progress}</h3>
                        <h5 class="seling-data-detail"></h5>
                      </div>
                    </div>
                    <div class="col-5 align-item-center">
                      <div class="header-title">建筑层数</div>
                      <div class="seling-report">
                        <h3 class="seling-data mb-1">{$floor_num}层</h3>
                        <if condition="($pvo.user_id eq $userid) OR ($pvo.demo neq 1)">
                        <a href="#" data-toggle="modal" data-target="#FloorModal" data-id="{$pvo.id}" data-backdrop="static"><span
                            id="floortip" data-toggle="tooltip" data-placement="bottom" title="设置项目楼层">设置楼层</span></a>
                        </if>
                      </div>
                    </div>
                  </div>
                </div>
                <!--end col-->
                <div class="col-lg-4 mb-2 mb-lg-0 mt-2">

                  <div class="row">
                    <div class="col-6">
                      <div class="header-title">CPN数量</div>
                      <div class="seling-report">
                        <h3 class="seling-data mb-1">{$device_num}</h3>
                        <p class="text-muted">更新时间</p>
                        <h5 class="seling-data-detail">{$pvo.updated_at}</h5>
                      </div>
                    </div>
                    <div class="col-6">
                      <div class="header-title">项目模板</div>
                      <div class="seling-report">
                        <h3 class="seling-data mb-1">{$modules[$pvo['module_ids']]}</h3>
                      </div>
                    </div>
                  </div>
                </div>
                <!--end col-->
              </div>
              <!--end row-->
            </div>
            <!--end f_profile-->
          </div>
          <!--end card-body-->

          <if condition="($pvo.user_id eq $userid) OR ($pvo.demo neq 1)">
          <div class="card-body">
            <div class="wrap">
              <div class="jctkr-label">
                <span>协同人员</span>
              </div>
              <div class="js-conveyor-example">
                <div class="img-group ml">
                  <volist name="helpers" id="helper">
                    <php>$headpic = $helper['image_url'] ? '__ROOT__'.$helper['image_url'] :
                      '__PUBLIC__/assets/images/users/user-0.jpg';</php>
                    <a class="user-avatar mr-2" href="#">
                      <img src="{$headpic}" data-toggle="tooltip" data-placement="top" title="{$helper.username}" class="rounded-circle thumb-md">
                      <span class="avatar-badge {$helper['is_online'] ? 'online' : 'offline'}"></span>
                    </a>
                  </volist>
                  <a class="user-avatar avatar-box  thumb-sam align-self-center " data-toggle="modal" data-target=".addFriends"
                    data-id="{$Think.request.id}">
                    <span class="avatar-title  bg-success rounded-circle"> <i class="mdi mdi-plus text-white "></i></span>
                  </a>
                </div>
                <!--end img-group-->
              </div>
            </div>
          </div>
          <!--end card-body-->
          </if>
        </div>
        <!--end card-->
      </div>
      <!--end col-->
    </div>
    <!--end row-->

    <div class="row">
      <div class="col-lg-3">
        <div class="card">
          <div class="card-body profile-nav">
            <div class="nav flex-column nav-pills" id="profile-tab" aria-orientation="vertical">
              <a class="nav-link active" id="profile-dash-tab" data-toggle="pill" href="#profile-dash" aria-selected="true">设备选择</a>
              <a class="nav-link" id="profile-activities-tab" data-toggle="pill" href="#profile-activities"
                aria-selected="false">操作记录</a>
              <a class="nav-link d-flex justify-content-between align-items-center" id="profile-tongji-tab" data-toggle="pill"
                href="#profile-tongji" aria-selected="false">
                选型统计

              </a>
              <a class="nav-link d-flex justify-content-between align-items-center" id="download-tab" data-toggle="pill"
                href="#download" aria-selected="false">
                设计成果
                <span id="design_count" class="badge badge-warning">{$design_count}</span>
              </a>
              <a class="nav-link mb-0" id="profile-settings-tab" data-toggle="pill" href="#profile-settings"
                aria-selected="false">项目设置</a>
            </div>
          </div>
          <!--end card-body-->
        </div>
        <!--end card-->
      </div>
      <!--end col-->

      <div class="col-lg-9">
        <div class="card">
          <div class="card-body">
            <div class="tab-content" id="profile-tabContent">
              <div class="tab-pane fade show active" id="profile-dash">
                <div class="align-item-center mt-2">
                  <h4 class="float-left header-title mt-0">CPN列表</h4>
                  <if condition="($pvo.user_id eq $userid) OR ($pvo.demo neq 1)">
                  <button class="float-right  btn btn-info  px-4 align-self-center addDevice-btn" data-id="">增加CPN</button>
                  </if>
                </div>
                <div style="clear:both"></div>
                <div class="mt-4 table-responsive">

                  <table id="datatable" class="table table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                    <thead>
                      <tr>
                        <th data-orderable="false"><input type="checkbox" id="chkall"></th>
                        <th>编号</th>
                        <th>id</th>
                        <th>CPN编号</th>
                        <th>被控设备编号</th>
                        <th>安装楼层</th>
                        <th>专用控制器类型</th>
                        <th>状态</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                  </table>
                </div>

                <!--end row-->
              </div>
              <!--end tab-pane-->
              <!-- 操作记录开始 -->
              <div class="tab-pane fade" id="profile-activities">
                <h4 class="mt-0 header-title mb-3">操作记录</h4>
                <div class="activity">

                </div>
                <!--end activity-->
              </div>
              <!--end tab-pane-->
              <!-- 选型统计开始 -->
              <div class="tab-pane fade" id="profile-tongji">
                <h4 class="mt-0 header-title mb-3">选型统计</h4>
                <div id="tongji" class="table-responsive">

                </div>
                <!--end table-responsive-->


              </div>
              <!--end tab-pen-->
              <!-- 设计成果-->
              <div class="tab-pane fade" id="download">
                <div class="mb-4 overflow-hidden">

                  <span class="input-icon icon-right">
                    <textarea id="version_intro" rows="4" class="form-control" placeholder="版本描述"></textarea>
                  </span>
                  <if condition="($pvo.user_id eq $userid) OR ($pvo.demo neq 1)">
                  <div class="float-right my-3">
                    <button type="button" class="btn btn-sm btn-primary text-light px-4 mb-0" onclick="saveVersion()">保存当前版本</button>
                  </div>
                  </if>

                </div>

                <div id="timeline"></div>

              </div>


              <!-- 项目设置 -->
              <div class="tab-pane fade" id="profile-settings">
                <div class="row">
                  <div class="col-lg-12">


                    <div class="">
                      <form id="profile" class="form-horizontal form-material mb-0">

                        <div class="form-group row">
                          <div class="col-md-3">
                            <empty name="pvo.img">
                              <input type="file" id="file" name="file" class="dropify" data-default-file="__PUBLIC__/assets/images/users/pro-1.png" />
                              <else />
                              <input type="file" id="file" name="file" class="dropify" data-default-file="__ROOT__/Uploads/project/{$pvo.img}?v={:time()}.png" />
                            </empty>
                          </div>
                          <div class="col-md-8">
                            <div class="form-group row">
                              <label for="example-url-input" class="col-sm-4 col-form-label text-right">项目编号</label>
                              <div class="col-sm-8">
                                <input class="form-control" type="text" id="project_code" name="project_code" value="{$pvo.project_code}">
                              </div>
                            </div>
                            <div class="form-group row ">
                              <label for="example-url-input" class="col-sm-4 col-form-label text-right">项目名称</label>
                              <div class="col-sm-8">
                                <input class="form-control" type="text" id="project_name" name="project_name" value="{$pvo.project_name}">
                              </div>
                            </div>
                            <div class="form-group row ">
                              <label for="example-url-input" class="col-sm-4 col-form-label text-right">项目地址</label>
                              <div class="col-sm-8">
                                <input class="form-control" type="text" id="project_addr" name="project_addr" value="{$pvo.project_addr}">
                              </div>
                            </div>
                          </div>


                        </div>

                        <div class="row">

                          <div class="col-md-6">
                            <div class="form-group row">
                              <label for="module_ids" class="col-sm-4 col-form-label text-right">项目阶段</label>
                              <div class="col-sm-8">
                                <select id="project_progress" name="project_progress" class="form-control">
                                  <option {$pvo['project_progress']=='方案设计' ? 'selected' : '' }>方案设计</option>
                                  <option {$pvo['project_progress']=='施工图设计' ? 'selected' : '' }>施工图设计</option>
                                  <option {$pvo['project_progress']=='监控软件设计' ? 'selected' : '' }>监控软件设计</option>
                                </select>
                              </div>
                            </div>
                          </div>
                          <div class="col-md-6">
                            <div class="form-group row">
                              <label for="module_ids" class="col-sm-4 col-form-label text-right">项目模板</label>
                              <div class="col-sm-8">
                                <select id="module_ids" name="module_ids" class="form-control">
                                  <foreach name="modules" item="voo">
                                    <option value="{$key}" {$pvo['module_ids']==$key ? 'selected' : '' }>{$voo}</option>
                                  </foreach>
                                </select>
                              </div>
                            </div>
                          </div>
                          <div class="col-md-12">
                            <div class="form-group row">
                              <label for="intro" class="col-sm-2 col-form-label text-right">项目描述</label>
                              <div class="col-sm-10">
                                <textarea class="form-control" id="intro" name="intro" rows="5">{$pvo.intro}</textarea>
                              </div>

                            </div>
                            <if condition="($pvo.user_id eq $userid) OR ($pvo.demo neq 1)">
                            <button type="button" class="btn btn-primary btn-sm text-light px-4 mt-3 float-right mb-0"
                              onclick="updateProfile()">更新</button>
                            </if>
                          </div>
                        </div>
                      </form>
                    </div>
                  </div>
                  <!--end col-->
                </div>
                <!--end row-->
              </div>
              <!--end tab-pane-->
            </div>
            <!--end tab-content-->
          </div>
          <!--end card-body-->
        </div>
        <!--end card-->
      </div>
      <!--end col-->
    </div>
    <!--end row-->
  </div><!-- container -->
  <div id="addDevice" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="addDevice" aria-hidden="true">
    <div class="modal-dialog ">
      <form class="" method="post" action="{:U('editDevice')}" target="ajaxifr">
        <div class="modal-content">

        </div><!-- /.modal-content -->
      </form>
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
  <div id="addFriends" class="modal addFriends fade" tabindex="-1" role="dialog" aria-labelledby="addFriends"
    aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title mt-0" id="myLargeModalLabel">协同邀请</h5>
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        </div>
        <div class="modal-body">

        </div>
      </div>
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
  <div class="modal fade" id="FloorModal" tabindex="1" role="dialog" aria-labelledby="FloorModal" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
      <form class="" method="post" action="{:U('editFloor')}" target="ajaxifr">
        <div class="modal-content">

        </div>
      </form>
    </div>
  </div>
  <form id="frm" action="{:U('setdevice')}" method="post">
    <input type="hidden" id="device_id" name="id">
    <input type="hidden" id="cpns" name="cpns">
  </form>
</block>
<block name="myscript">
  <script src="__PUBLIC__/assets/plugins/moment/moment.js"></script>
  <script src="__PUBLIC__/assets/plugins/dropify/js/dropify.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/ticker/jquery.jConveyorTicker.min.js"></script>
  <script src="__PUBLIC__/assets/pages/jquery.profile.init.js"></script>
  <script src="__PUBLIC__/assets/js/jquery.core.js"></script>
  <script src="__PUBLIC__/assets/plugins/datatables/jquery.dataTables.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/datatables/dataTables.bootstrap4.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/datatables/dataTables.bootstrap4.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/datatables/dataTables.rowReorder.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/datatables/dataTables.buttons.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/datatables/buttons.bootstrap4.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/repeater/jquery.repeater.min.js"></script>
  <script src="__PUBLIC__/assets/plugins/upload/ajaxfileupload.js"></script>
  <script>
    var project_id = "{$Think.request.id}";
   
    var table = $('#datatable').DataTable({
      "ajax": "{:U('getCpnList','','')}/project_id/" + project_id,
      "language": {
        "url": "__PUBLIC__/web/js/datatables.Chinese.json"
      },
      "columns": [
        { "data": "checkbox" },
        { "data": "id", className: 'sort' },
        { "data": "rid" },
        { "data": "cpn_sn" },
        { "data": "device_sn" },
        { "data": "floor_name" },
        { "data": "group_name" },
        { "data": "status" },
        { "data": "action" },
      ],
      "stateSave": true,
      "order": [[1, 'asc']],
      columnDefs: [
        { targets: 2, visible: false }
      ],
      
      rowReorder: {
        selector: '.sort',
        dataSrc: 'id',
        snapX: true
      },
      <if condition="($pvo.user_id eq $userid) OR ($pvo.demo neq 1)">
      "initComplete": function() {
        $('.dataTables_info').before('<button id="bat_btn" class="btn btn-info btn-sm px-4">批量设置</button>');
      }
      </if>
    });
    //console.log(table)
   
    
    /*
    $('#datatable').on( 'page.dt', function () {
        var info = table.page.info();
        sessionStorage.setItem('page', info.page);
    } );
    */

    table.on('row-reorder', function (e, diff, edit) {
      var exchangeList = [];
      var rowData;
      //var row = edit.triggerRow.data();
      //console.log(diff);

      for (var i = 0, ien = diff.length; i < ien; i++) {
        rowData = table.row(diff[i].node).data();

            exchangeList.push({'id': rowData.rid, 'sort': diff[i].newPosition});
        }
        //console.log(exchangeList);
       reOrder(exchangeList);
    });
    $(".toolbar").html('<b style="color:red">自定义文字、图片等等</b>');
    function reOrder(param) {
      $.ajax({
        type: "POST",
        url: "{:U('saveSort')}",
        data: { "data": param },
        "statusCode": {
          404: function () { alert("您访问的链接不存在"); },
          500: function () { alert("未知错误，请稍后再试"); }
        },
        success: function (res) {
          if (res == '1') {
            notify('success', '提示', '排序成功！');
          } else {
            notify('error', '提示', '排序失败！');
          }

        }
      });
    }

    function goPage(p) {
      table.page(p).draw(false);
    }

    $('.addDevice-btn').on('click', function () {
      <eq name="floor_num" value="0">
        notify('error', '提示', '还没有设置楼层，请先设置！');
		    $('#floortip').tooltip('show');
      <else />
        $('#addDevice').modal({
          backdrop: 'static',
    })
      </eq>
    });

    $('#addDevice').on('show.bs.modal', function (e) {
      var obj = $(e.relatedTarget);
      var id = obj.data('id');
      var _this = this;
      var url = "{:U('editDevice')}";
      $.ajax({
        type: 'GET',
        url: url,
        data: { project_id: project_id, id: id }
      }).then(function (data) {
        $(_this).find('.modal-content').html(data);
      });
    })

    $('#addDevice').on('shown.bs.modal', function (e) {
      $('#cpn_sn').tooltip('show');
    })

    $('#addFriends').on('show.bs.modal', function (e) {
      var obj = $(e.relatedTarget);
      var id = obj.data('id');
      var url = "{:U('addFriend')}";
      var _this = this;
      $.get(url, { project_id: id }, function (res) {
        $(_this).find('.modal-body').html(res);
      });
    });

    $('#profile-tab').on('show.bs.tab', function (e) {
      var obj = e.target;
      if (obj.id == 'profile-activities-tab') {
        server(1);
      } else if (obj.id == 'profile-tongji-tab') {
        var url = "{:U('tongji')}";
        $.get(url, { project_id: project_id }, function (res) {
          $('#tongji').html(res);
        })
      } else if (obj.id == 'download-tab') {
        var url = "{:U('version')}";
        $.getJSON(url, { project_id: project_id }, function (res) {
          $('#timeline').html(res.data);
          $('#design_count').text(res.count);
        })
      }
    });

    $('#FloorModal').on('show.bs.modal', function (e) {
      var obj = $(e.relatedTarget);
      var id = obj.data('id');
      var url = "{:U('editFloor')}";
      var _this = this;
      $.get(url, { project_id: id }, function (res) {
        $(_this).find('.modal-content').html(res);
      });
    });

    $(document).on('click', '.yaoqing', function () {
      var url = "{:U('invite')}";
      var userid = $(this).data('userid');
      var _this = this;
      if (confirm('确认邀请此用户吗？')) {
        $.post(url, { project_id: project_id, userid: userid }, function (res) {
          if (res == '1') {
            $(_this).text('已邀请');
            $(_this).prop('disabled', true);
            notify('success', '提示', '发送邀请消息成功！');
          } else {
            notify('error', '提示', '发送邀请消息失败！');
          }
        });
      }
    });

    function delDevice(id) {
      var url = "{:U('delDevice')}";
      if (confirm('确认删除此设备记录吗？')) {
        $.get(url, { id: id }, function (res) {
          if (res == '1') {
            table.ajax.reload( null, false );
          }
        });
      }
    }

    function copyDevice(id) {
      var url = "{:U('copydevice')}";
      if (confirm('确认复制此设备记录吗？')) {
        $.get(url, { id: id }, function (res) {
          if (res == '1') {
            table.ajax.reload( null, false );
          }
        });
      }
    }

    function server(p) {
      var id = "{$Think.request.id}";
      var url = "{:U('getLogs')}";
      $.get(url, { id: id, p: p }, function (res) {
        $('#profile-activities').find('.activity').html(res);
      });
    }

    function queryUser() {
      var url = "{:U('queryUser')}";
      var username = $.trim($('#username').val());
      $.post(url, { project_id: project_id, username: username }, function (res) {
        $('.usercard').removeClass('d-none');
        $('.userlist').html(res);
        $('.invitetip').tooltip('show');
      });
    }
    <if condition="($pvo.user_id eq $userid) OR ($pvo.demo neq 1)">
    //上传文件
    function updateProfile() {
      var data = {};
      data.id = project_id;
      data.project_code = $('#project_code').val();
      data.project_name = $('#project_name').val();
      data.project_addr = $('#project_addr').val();
      data.project_progress = $('#project_progress').val();
      data.module_ids = $('#module_ids').val();
      data.intro = $('#intro').val();

      var url = "{:U('updateProfile')}";
      $.ajaxFileUpload({
        url: url, //用于文件上传的服务器端请求地址
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: 'file', //文件上传域的ID
        dataType: 'json', //返回值类型 一般设置为json
        data: data,
        success: function (data, status)  //服务器成功响应处理函数
        {
          if (data.status == '1') {
            if (data.img.length > 0) {
              $('#project_img').attr('src', root_url + '/Uploads/project/' + data.img + '?v=' + (new Date).getTime());
            }
            notify('success', '提示', data.info);
          } else {
            notify('error', '提示', data.info);
          }
        },
        error: function (data, status, e)//服务器响应失败处理函数
        {
          //notify('error', '提示', '上传失败：' + e);
        },
        complete: function (data, status) {
          var info = JSON.parse(data.responseText).info;
          notify('success', '提示', info);
        }
      })
    }

    //保存当前版本
    function saveVersion() {
      var url = "{:U('saveVersion')}";
      var intro = $('#version_intro').val();
      $.post(url, { project_id: project_id, intro: intro }, function (res) {
        if (res) {
          $('#timeline').html(res.data);
          $('#design_count').text(res.count);
          $('version_intro').val('');
        }
      }, 'json');
    }
    </if>
    
    function goto(p) {
      var url = "{:U('version')}";
      $.getJSON(url, { project_id: project_id, p: p }, function (res) {
        $('#timeline').html(res.data);
        $('#design_count').text(res.count);
      });
    }

    $(document).on('click', '.shanchu', function () {
      var url = "{:U('delVersion')}";
      var id = $(this).data('id');
      if (confirm('确认删除此版本记录吗？')) {
        $.post(url, { id: id }, function (res) {
          if (res) {
            $('#timeline').html(res.data);
            $('#design_count').text(res.count);
            $('version_intro').val('');
          }
        }, 'json');
      }
    });

    $(function () {
      $('[data-toggle="tooltip"]').tooltip();

      $('#chkall').on('click', function(){
        var ids = [];

        if(this.checked){
          $('.chk').not(':disabled').prop('checked', true);
        } else {
          $('.chk').prop('checked', false);
          $('.chk').prop('disabled', false);
        }

        $('.chk:checked').each(function(){
          ids.push($(this).val());
        });

        $('#cpns').val(ids.join(','));
       
      });

      $(document).on('click', '#bat_btn', function(){
        var ids = [];
        var ctype = [];
        $('.chk:checked').each(function(){
          ids.push($(this).val());
          ctype.push($(this).data('type'));
        });

        if(ids.length == 0){
          notify('error', '提示', '请选择要批量设置的设备！');
          return false;
        }

        if(distinct(ctype).length > 1){
          notify('error', '提示', '批量设置类型不相同！');
          return false;
        } else {
          $('#device_id').val(ids[0]);
          document.getElementById('frm').submit();
        }
      });

      $(document).on('click', '.chk', function(){
        var ids = [];
        var cpn_type = $(this).data('type');

        $('.chk:checked').each(function(){
          ids.push($(this).val());
        });

        $('#cpns').val(ids.join(','));

        if($('.chk:checked').length == 0){
          $('.chk').prop('disabled', false);
          $('#chkall').prop('checked', false);
        } else {
          if(this.checked){
            $('.chk').not('.chk_'+cpn_type).prop('checked', false);
            $('.chk').not('.chk_'+cpn_type).prop('disabled', true);
          }
        }
      });

      $(document).on('click', '.setdevice', function () {
        var ids = [];
        var ret = true;
        var cpn_type = $(this).data('type');
        $('#device_id').val($(this).data('id'));
        $('.chk:checked').each(function () {
          if (cpn_type != $(this).data('type')) {
            ret = false;
            return false;
          }
          ids.push($(this).val());
        });
        if (ret) {
          $('#cpns').val(ids.join(','));
          document.getElementById('frm').submit();
        } else {
          notify('error', '提示', '选择设备类型与当前设置类型不一致！');
        }
      })
    })

    function distinct(arr) {
			return Array.from(new Set(arr))
		}
  </script>

</block>